﻿namespace DimensionsHelper.LanguageService.Syntax;

public abstract class MetadataLabeledObject : Declaration
{
    private SyntaxList<MetadataLabel>? _labels;
    private SyntaxList<MetadataStyle>? _labelStyles;


    private SyntaxList<MetadataProperties>? _properties;
    private SyntaxList<MetadataStyle>? _styles;
    private SyntaxList<MetadataTemplates>? _templates;

    internal MetadataLabeledObject(SyntaxKinds kind, SyntaxToken declareKeywordToken, Identifier name,
        SyntaxNode? parent) :
        base(kind, declareKeywordToken, name, parent)
    {
    }


    public override bool IsMetadata => true;


    public IReadOnlyList<MetadataLabel> Labels =>
        _labels == null ? new List<MetadataLabel>() : _labels;


    public IReadOnlyList<MetadataProperties> Properties =>
        _properties == null ? new List<MetadataProperties>() : _properties;


    public IReadOnlyList<MetadataTemplates> Templates =>
        _templates == null ? new List<MetadataTemplates>() : _templates;


    public IReadOnlyList<MetadataStyle> Styles =>
        _styles == null ? new List<MetadataStyle>() : _styles;


    public IReadOnlyList<MetadataStyle> LabelStyles =>
        _labelStyles == null ? new List<MetadataStyle>() : _labelStyles;


    public void AddLabel(MetadataLabel label)
    {
        AddChildMember(ref _labels, label);
    }


    public void AddProperties(MetadataProperties properties)
    {
        AddChildMember(ref _properties, properties);
    }


    public void AddTemplates(MetadataTemplates templates)
    {
        AddChildMember(ref _templates, templates);
    }


    public void AddStyle(MetadataStyle style)
    {
        AddChildMember(ref _styles, style);
    }


    public void AddLabelStyle(MetadataStyle style)
    {
        AddChildMember(ref _labelStyles, style);
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        base.AcceptVisitor(visitor);
        AcceptList(visitor, Properties);
        AcceptList(visitor, Templates);
        AcceptList(visitor, Labels);
        AcceptList(visitor, Styles);
        AcceptList(visitor, Labels);
    }
}